var well={};
well.currentObj;
well.loadList=function (pageNo,isfirst){
	var queryStr=$("#well_queryText").val();
	$('#wellTable').empty();
	var params = {pageSize:3,pageNo:pageNo,queryStr:queryStr};
	var config={columns:[{
		headerText:'井名',
		name:'name'
	},{
		headerText:'地理位置',
		name:'location'
	},{
		headerText:'井类别',
		name:'class_'
	},{
		headerText:'井队号',
		name:'teamNumber'
	},{
		headerText:'完井日期',
		name:'dateFinishWell'
	},{
		headerText:'垂深/米',
		name:'verticalDepthReal'
	},{
		headerText:'斜深/米',
		name:'inclinedDepthReal'
	},{
		headerText:'注采方式',
		name:'produceMethod'
	},{
		headerText:'录入时间',
		name:'dateInput'
	},{
		headerText:'录入人',
		name:'owner'
	},{
		headerText:'操作',
		name:'',
		renderer:function(str) {
		return '<input type="button" onclick="well.openDetailDialog('+this.id+')" value="查看">'+
		'<input type="button" onclick="well.openUpdateDialog('+this.id+')" value="修改">'+
		'<input type="button" onclick="well.doDelete('+this.id+')" value="删除">';
	} 
	}
	],url:basePath+'app/well/loadList',params:params};
	$('#wellTable').table(config,true,isfirst);
}
//新增操作
well.openAddDialog=function (){
	well.cleanAddDialog();
	$("#addWellDialog").dialog({ modal: true ,width: 1100});
}
well.cleanAddDialog=function (){
	document.getElementById("add_form").reset();
	$("#add_dateBeginDrill").datepicker();
	$("#add_dateEndDrill").datepicker();
	$("#add_dateFinishWell").datepicker();
}
well.callback=function (){
	try{
		$("#addWellDialog").dialog("close");
	}catch(error){
	}
	try{
		$("#updateWellDialog").dialog("close");
	}catch(error){
	}
}
//查看操作
well.openDetailDialog=function (wellId){
	well.refreshDetailDialog(wellId);
	$("#detailWellDialog").dialog({ modal: false ,width: 1100});
}
well.refreshDetailDialog=function (wellId){
	var wg;
	for(var i in window.gridcache){
		if(wellId==window.gridcache[i].id){
			wg=window.gridcache[i];
			break;
		}
	}
	$("#detail_id").val(wg.id);
	$("#detail_name").val(wg.name);
	$("#detail_location").val(wg.location);
	$("#detail_gouzaoLoc").val(wg.gouzaoLoc);
	$("#detail_basisDrill").val(wg.basisDrill);
	$("#detail_objective").val(wg.objective);
	$("#detail_class_").val(wg.class_);
	$("#detail_teamNumber").val(wg.teamNumber);
	$("#detail_method").val(wg.method);
	$("#detail_dateBeginDrill").val(wg.dateBeginDrill);
	$("#detail_dateEndDrill").val(wg.dateEndDrill);
	$("#detail_dateFinishWell").val(wg.dateFinishWell);
	$("#detail_verticalDepthDesign").val(wg.verticalDepthDesign);
	$("#detail_inclinedDepthDesign").val(wg.inclinedDepthDesign);
	$("#detail_verticalDepthReal").val(wg.verticalDepthReal);
	$("#detail_inclinedDepthReal").val(wg.inclinedDepthReal);
	$("#detail_wellLayer").val(wg.wellLayer);
	$("#detail_basisFinishDrill").val(wg.basisFinishDrill);
	$("#detail_remark").val(wg.remark);
	$("#detail_produceMethod").val(wg.produceMethod);
	$("#detail_dateInput").text(wg.dateInput);
	$("#detail_owner").text(wg.owner);
}
//修改操作
well.openUpdateDialog=function (wellId){
	well.refreshUpdateDialog(wellId);
	$("#updateWellDialog").dialog({ modal: true ,width: 1100});
}
well.refreshUpdateDialog=function (wellId){
	var wg;
	for(var i in window.gridcache){
		if(wellId==window.gridcache[i].id){
			wg=window.gridcache[i];
			break;
		}
	}
	well.currentObj=wg;
	$("#update_id").val(wg.id);
	$("#update_name").val(wg.name);
	$("#update_location").val(wg.location);
	$("#update_gouzaoLoc").val(wg.gouzaoLoc);
	$("#update_basisDrill").val(wg.basisDrill);
	$("#update_objective").val(wg.objective);
	$("#update_class_").val(wg.class_);
	$("#update_teamNumber").val(wg.teamNumber);
	$("#update_method").val(wg.method);
	$("#update_dateBeginDrill").val(wg.dateBeginDrill);
	$("#update_dateEndDrill").val(wg.dateEndDrill);
	$("#update_dateFinishWell").val(wg.dateFinishWell);
	$("#update_verticalDepthDesign").val(wg.verticalDepthDesign);
	$("#update_inclinedDepthDesign").val(wg.inclinedDepthDesign);
	$("#update_verticalDepthReal").val(wg.verticalDepthReal);
	$("#update_inclinedDepthReal").val(wg.inclinedDepthReal);
	$("#update_wellLayer").val(wg.wellLayer);
	$("#update_basisFinishDrill").val(wg.basisFinishDrill);
	$("#update_remark").val(wg.remark);
	$("#update_produceMethod").val(wg.produceMethod);
	$("#update_dateInput").text(wg.dateInput);
	$("#update_owner").text(wg.owner);
	$("#update_dateBeginDrill").datepicker();
	$("#update_dateEndDrill").datepicker();
	$("#update_dateFinishWell").datepicker();
}
//删除操作
well.doDelete=function (wellId){
	var i=window.confirm("确认删除？");
	if(i==true){
		$.post(basePath+"app/well/doDeleteWell", {wellId:wellId}, function(data) {
			well.loadList();//修改刷新为当前页
		});
	}
}
$(function() {
	currentModule=well;//当前模块
	well.loadList(1,true);
	$("#wellQuery").bind("keyup",function (event){
		if (event.keyCode=="13"){
			well.loadList(1);
		}
	});
});